﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ExcelToOracle
{
    public partial class SelectTemplateDialog : Form
    {
        public ImportTemplate SelectedTemplate { get; set; }

        public SelectTemplateDialog()
        {
            InitializeComponent();

            _listSheet.DataSource = ImportTemplate.LoadAll();
        }

        private void _btnSelect_Click(object sender, EventArgs e)
        {
            if (_listSheet.SelectedItem == null)
            {
                MessageBox.Show(
                    "选择模版",
                    "提示",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
                return;
            }
            if (MessageBox.Show(
                "是否选择模版 [" + ((ImportTemplate)_listSheet.SelectedItem).DbTable + "]?",
                "提示",
                MessageBoxButtons.OKCancel,
                MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
            {
                SelectedTemplate = (ImportTemplate)_listSheet.SelectedItem;
                DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }

        private void _listSheet_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (_listSheet.SelectedItem != null)
            {
                if (MessageBox.Show(
                    "是否选择模版 [" + ((ImportTemplate)_listSheet.SelectedItem).DbTable + "]?",
                    "提示",
                    MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
                {
                    SelectedTemplate = (ImportTemplate)_listSheet.SelectedItem;
                    DialogResult = System.Windows.Forms.DialogResult.OK;
                }
            }
        }
    }
}
